package com.lry.properties;

import com.lry.bean.dingding.DingDingMarkdownNotice;
import com.lry.bean.dingding.DingDingNotice;
import com.lry.bean.dingding.DingDingTextNotice;
import com.lry.enums.DingdingTextType;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "ea.dingding")
public class DingDingProperties {

    private boolean enable = false;

    private String[] phones;

    private String accessToken;

    private boolean enableSignatureCheck;

    private String signSecret;

    private DingdingTextType dingdingTextType = DingdingTextType.TEXT;

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public String[] getPhones() {
        return phones;
    }

    public void setPhones(String[] phones) {
        this.phones = phones;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public boolean isEnableSignatureCheck() {
        return enableSignatureCheck;
    }

    public void setEnableSignatureCheck(boolean enableSignatureCheck) {
        this.enableSignatureCheck = enableSignatureCheck;
    }

    public String getSignSecret() {
        return signSecret;
    }

    public void setSignSecret(String signSecret) {
        this.signSecret = signSecret;
    }

    public DingdingTextType getDingdingTextType() {
        return dingdingTextType;
    }

    public void setDingdingTextType(DingdingTextType dingdingTextType) {
        this.dingdingTextType = dingdingTextType;
    }

    public DingDingNotice generateDingdingNotice(String msg, String title) {
        switch (dingdingTextType) {
            case MARKDOWN:
                return new DingDingMarkdownNotice(msg, title, phones);
            case TEXT:
                return new DingDingTextNotice(msg, phones);
        }
        // never happen;
        return null;
    }
}
